package net.dodoman;

import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;

public class Server implements SumEngine {

	/**
	 * This is the implementation of the sum remote method.
	 * 
	 */
	public Integer sum(Integer a, Integer b) throws RemoteException {
		return a + b;

	}

	public static void main(String[] args) {
		// starts up the security manager
		if (System.getSecurityManager() == null) {
			System.setSecurityManager(new SecurityManager());
		}

		try {
			// create a new Server (remote object) instance
			Server engine = new Server();

			// get the stub from remote object
			SumEngine stub = (SumEngine) UnicastRemoteObject.exportObject(
					engine, 0);

			// get the reference to RMI registry
			Registry registry = LocateRegistry.getRegistry();

			// registry the remote object
			registry.rebind("SUM", stub);

			System.out.println("ComputeEngine bound");

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
